<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图形旋转</title>
    <style>
        #cs{
            border:1px solid red;
        }
    </style>
</head>
<body>
    <canvas id="cs" width="800" height="500"></canvas>
    <script>
        let cs = document.getElementById("cs");
        let ctx = cs.getContext("2d");
        let i = 0;
        setInterval(function(){
            ctx.clearRect(0,0,800,500);
            ctx.save();
            ctx.translate(350,225);
            ctx.rotate(Math.PI / 180 * i);
            ctx.globalAlpha=0.1;
            ctx.fillStyle = `rgb(
                ${parseInt(Math.random() * 256)}
            ,${parseInt(Math.random() * 256)},
            ${parseInt(Math.random() * 256)})`;
            ctx.fillRect(-50,-25,100,50);
            ctx.restore();
            i++;
        },50);
        
    </script>
</body>
</html>